/** * @license * Copyright 2020 JBoss Inc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Topic } from "apicurio-ts-core"; import { Document } from "apicurio-data-models"; /** * A service to manage a collection of APIs that should be loaded to accommodate various bits * of functionality, but primarily to assist with resolving external references. This service * itself does not resolve external resources, but requires a helper for that. * * TODO also maintain a list of errors - populated when we fail to resolve a resource URL (and why) */ export declare class ApiCatalogService { private apiCache; private readonly changeTopic; private fetchCounter; private fetcher; /** * Constructor. */ constructor(); /** * Sets the fetcher for the service. * @param fetcher */ setFetcher(fetcher: (externalReference: string) => Promise): void; /** * Called to refresh the API cache. This will remove any cached APIs that are not needed by * the given document. * @param document */ private refresh; /** * Called to reset the API cache. This will remove any cached APIs that are not needed by * the given document. * @param document */ reset(document: Document): void; /** * Called when the document changes in any way. When that happens, we need to detect whether any new * external references have been added. If so, we need to fetch them and update the cache. * @param document */ update(document: Document): void; /** * Return the topic that consumers can use to listen when the contents of the api cache changes. */ changes(): Topic; /** * Finds all the $refs anywhere in the given document. * @param document */ private getAllRefs; /** * Fetches the given external reference (asynchronously) and caches the result if appropriate. * @param externalRef */ private fetchAndCache; /** * Parses the given response body into a JS object. This should support both JSON and YAML content. If * parsing fails we should log an error and return null. That will indicate to any consumers of the * cache that there *should* be an entry for the content but that the content failed to be fetched. * @param body */ private parseContent; /** * Extracts the design id from the given external ref of the form: apicurio:173827 * @param externalRef */ private toDesignId; /** * Caches the given JS object content. Also potentially fires a "changed" event. * @param content */ private cacheContent; /** * Called to lookup a resource stored in the catalog. Returns a JS object if one is found or null * if not found. * @param resourceUrl */ lookup(resourceUrl: string): any; }